const express = require('express')
const app = express()


const cors = require('cors')
app.use(cors())

/* 1-导入数据库包 */
var mysql = require('mysql');
/* 2-创建数据库连接池 */
var conn = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: 'bigevent'
});


app.get('/qq', (req, res) => {
    //  根据id值查询数据
    const id = req.query.id
    const hobby = req.query.hobby
    // var sql = 'select  *  from  user where  id='+ id

    /* 删除数据 */
    /* 3-执行sql语句 */
    
   // var sql = 'delete  from   user where  id=?'
    //  conn.query(sql,id, (error, result, fields) => {
    //      if (error) throw error;
    //      if(result.affectedRows==1){
    //          console.log(result, 9999)
    //          res.send('删除成功')
    //      }
    //  })

 
   /* 添加 */
    // var sql = `insert  into user(username,hobby,age) values('bbbb', '打豆豆2222',?)`
    // conn.query(sql, '28', (error, result, fields) => {
    //     console.log(result, 6666)
    //     if (error) throw error;
    //     if (result.affectedRows == 1) {
    //         res.send('添加成功')
    //     }
    // })
    var sql=`update user  set hobby=?  where id=? `
    conn.query(sql, [hobby,id], (error, result, fields) => {
        res.send('修改成功')
    })
})
app.listen(999, () => {
    console.log('服务器:http://127.0.0.1:999')
})